#ifndef CURTAIN_CONTROL_H
#define CURTAIN_CONTROL_H

#include <QDialog>
#include <QGraphicsScene>
#include "mypixmapitem.h"
#include <QTableView>
#include <QTouchEvent>
#include <QTime>
#include <QStandardItemModel>
#include <modbusservice.h>
#include <QSqlQuery>
#include <QMessageBox>
#include "mainwindow.h"
#include "QMovie"
namespace Ui {
class Curtain_Control;
}

class Curtain_Control : public QDialog
{
    Q_OBJECT

public:
    explicit Curtain_Control(QWidget *parent = 0);
    ~Curtain_Control();
    void startInit();
    QSqlQueryModel sqlmodel ; //保存结果集

    QString gaintime();

    void sleep_ms(unsigned int msec);
private slots:
    void queryTable();

    void deal_setting();

    void curtain_oc_Timeout();

    void deal_key();

    void deal_adc();

    void deal_message();

    void sql_insert_data(QString type, QString message);  //数据库插入一条数据

    void on_Parameter_set_Button_clicked();

    void on_Alarm_information_Button_clicked();

    void on_pushButton_mainPage_clicked();

    void on_Button_backui_clicked();

    void on_pushButton_up_clicked();

    void on_pushButton_down_clicked();

    void on_pushButton_stop_clicked();

    void on_lineEdit_uptime_cursorPositionChanged(int arg1, int arg2);

    void on_lineEdit_downtime_cursorPositionChanged(int arg1, int arg2);

    void on_lineEdit_max_uptime_cursorPositionChanged(int arg1, int arg2);

    void on_lineEdit_max_downtime_cursorPositionChanged(int arg1, int arg2);

    void on_pushButton_query_clicked();

    void on_Button_adc_clicked();

    void on_lineEdit_downtime_editingFinished();

    void on_lineEdit_uptime_editingFinished();

    void on_lineEdit_max_uptime_editingFinished();

    void on_lineEdit_max_downtime_editingFinished();

private:
    Ui::Curtain_Control *ui;

    MyPixMapItem *curtain1,*curtain2;//窗帘布图片
    MyPixMapItem *background;//窗帘背景图片
    QGraphicsScene scene;//动画场景

    float curtain_open_percent;

    int delete_count; // 关闭窗口是需要结束当前的操作 //不能有循环
    int curtain_update;  //门可不可以更新状态  暂停按钮决定
    bool curtain_up;  //门上升状态  true 可以上升  false 不能上升
    bool curtain_down;  //门下降状态  true 可以上升  false 不能上升

    int curtain_time_up = 100;
    int curtain_time_down = 100;
    int max_uptime = 10000;
    int max_downtime=10000;

    QDateTime current_date_time; //获取当前时间
    QString current_time;  //获取当前时间

    int oc_Timeout_count = 0; //设置 过载函数的计数器  只有最后一次点击有效

    QTimer *oc_TimeoutTimer;  //处理maxtime是否过载的定时器
    QTimer *port_informationTimer;  //串口通信的定时器
    int MOD_message_count;  //处理串口通信的计数器

    QString tablename="EVENTTABLE";

    char KbdStatus=0;//获取按键状态
    int Last_key_value;  //按一次只触发一次
    char LEDSValue;//存放led要改变的值

    int Open_in_place;  //按键1控制的打开限位
    int Closed_in_place;  //按键2控制的关闭限位
    int Close_the_overload;  //按键3控制的打开过载
    int Open_the_overload;  //按键4控制的打开过载

    bool adc_count; //按键控制是否采用adc采样设置开度


    QTimer *KbdScanTimer;//按键扫描定时器
    QTimer *adcScanTimer;//ADC扫描定时器
    QTimer *settingTimer;//
    int rt;  //adc采样需要的变量
    unsigned long adc_vol = 0;

    //图片切换时需要的几个变量进行声明
    QImage Image_greenon;
    QImage Image_greenoff;
    QPixmap pixmap_greenon;
    QPixmap pixmap_greenoff;
    QPixmap fitpixmap_greenon;
    QPixmap fitpixmap_greenoff;


    QImage Image_redon;
    QImage Image_redoff;
    QPixmap pixmap_redon;
    QPixmap pixmap_redoff;
    QPixmap fitpixmap_redon;
    QPixmap fitpixmap_redoff;

    QMovie* movie;
};

#endif // CURTAIN_CONTROL_H
